package cn.edu.hbwe.book.servlet.Notice;

import java.io.IOException;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.hbwe.book.entity.Notice;
import cn.edu.hbwe.book.service.notice.NoticeService;

/**
 *	后台添加公告的servlet
 */
@WebServlet("/AddNoticeServlet")

public class AddNoticeServlet extends HttpServlet{

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException  {
		this.doPost(request,response);
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException  {
		
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		Notice notice = new Notice();
		String title = request.getParameter("title");
		String details = request.getParameter("details");
		
		String t = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
		notice.setTitle(title);
		notice.setDetails(details);
		notice.setN_time(t);
		
		
		
			try {
				NoticeService nd=new NoticeService();
				nd.addNotice(notice);
				request.getRequestDispatcher("/ListNoticeServlet").forward(request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		


	}
}

